package com.sx.fams.country.action;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.alibaba.fastjson.JSONArray;
import com.opensymphony.xwork2.ModelDriven;
import com.sx.core.BaseAction;
import com.sx.fams.country.biz.ICountryBiz;
import com.sx.fams.country.entity.CountryEntity;
import com.sx.feesunit.exception.SXException;

@SuppressWarnings("serial")
public class CountryAction extends BaseAction implements ModelDriven<CountryEntity> {
	private CountryEntity country = new CountryEntity();
	private ICountryBiz countrybiz;
	private Log log = LogFactory.getLog(this.getClass());
	/**
	 *获取国家和地区数据为GridPanel列表 
	 **/
	public void findCoutryinfosByCpid() throws SXException{
		try {
			String name = "Country.findCountryInfos";
			String countsquery = "Country.findCountryInfosCounts";
			String counts = countrybiz.findCountryInfosCounts(countsquery, country);
			List<CountryEntity> list = countrybiz.findCoutryInfos(name, country);
			String str = JSONArray.toJSONString(list);
			outJsonString("{totalCount:"+counts+",data:"+str+"}");
		} catch (Exception e) {
			outJsonString("{totalCount:0,data:[]}");
			log.error("获取国家和地区数据为GridPanel列表",e);
			throw new SXException(e);
		}
	}
	/***
	 *获取国家和地区数据信息 
	 ***/
	public void findCoutryInfos() throws SXException{
		try {
			String name = "Country.findCountryInfos";
			List<CountryEntity> list = countrybiz.findCoutryInfos(name, country);
			for (CountryEntity cou : list) {
				cou.setLeaf(true);
			}
			String str = JSONArray.toJSONString(list);
			outJsonString(str);
		} catch (Exception e) {
			outJsonString("[]");
			log.error("获取国家和地区信息",e);
			throw new SXException(e);
		}
		
	}
	
	
	/**
	 * @return the countrybiz
	 */
	public ICountryBiz getCountrybiz() {
		return countrybiz;
	}

	/**
	 * @param countrybiz the countrybiz to set
	 */
	public void setCountrybiz(ICountryBiz countrybiz) {
		this.countrybiz = countrybiz;
	}

	public CountryEntity getModel() {
		// TODO Auto-generated method stub
		return country;
	}

}
